package com.rh.bmw4s.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.github.jdsjlzx.ItemDecoration.DividerDecoration;
import com.github.jdsjlzx.interfaces.OnItemClickListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.rh.bmw4s.R;
import com.rh.bmw4s.bean.BrandBean;
import com.rh.bmw4s.inter.OpenItemIner;

import java.util.List;

/**
 * Created by Administrator on 2017/9/26.
 */

public class CategoryDetailAdapter extends ListBaseAdapter<BrandBean> {
    Context context;
    OpenItemIner iner;
    public CategoryDetailAdapter(Context context) {
        super(context);
        this.context=context;
        this.iner= (OpenItemIner) context;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_category;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        final BrandBean brandBean = getDataList().get(position);
        LRecyclerView recyclerView = holder.getView(R.id.recyclerView);
        TextView TvTitle = holder.getView(R.id.tv_title);
        TvTitle.setText(brandBean.getLetters());
        final List<BrandBean.BrandsBean> brands = brandBean.getBrands();
        if(brands==null){return;}
        if(!brands.isEmpty()){
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
            CategoryContentAdapter mAdapter = new CategoryContentAdapter(context);
            mAdapter.setDataList(brands);
            LRecyclerViewAdapter lRecyclerViewAdapter = new LRecyclerViewAdapter(mAdapter);
            recyclerView.setAdapter(lRecyclerViewAdapter);
            DividerDecoration divider = new DividerDecoration.Builder(context)
//                    .setHeight(R.dimen.divider_height_1)
                    .setPadding(R.dimen.divider_padding)
                    .setColorResource(R.color.line_1)
                    .build();
            recyclerView.addItemDecoration(divider);
            recyclerView.setLoadMoreEnabled(false);
            recyclerView.setPullRefreshEnabled(false);
            recyclerView.refresh();
            lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    iner.itemDetailClick(brands.get(position));
                }
            });
        }
    }
}
